package com.anivia.system.auth.controller.admin;

import com.anivia.common.core.model.vo.R;
import com.anivia.common.web.satoken.admin.SaAdminCheckLogin;
import com.anivia.system.auth.model.dto.DeptAddOrUpdateDTO;
import com.anivia.system.auth.service.IDepartmentInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

/**
 * 部门信息 前端控制器
 *
 * @author wangj
 */
@Tag(name = "部门管理")
@RestController
@RequestMapping("/admin/dept")
public class DepartmentInfoController {
    @Resource
    private IDepartmentInfoService departmentInfoService;

    @Operation(summary = "新增或更新部门")
    @SaAdminCheckLogin
    @PostMapping("saveOrUpdate")
    private R saveOrUpdate(@RequestBody @Valid DeptAddOrUpdateDTO dto) {
        departmentInfoService.saveOrUpdate(dto);
        return R.ok();
    }

    @Operation(summary = "删除部门")
    @SaAdminCheckLogin
    @PostMapping("delete/{id}")
    private R delete(@PathVariable Integer id) {
        departmentInfoService.delete(id);
        return R.ok();
    }

    @Operation(summary = "查询部门")
    @SaAdminCheckLogin
    @GetMapping("details/{id}")
    private R details(@PathVariable Integer id) {
        return R.ok(departmentInfoService.getById(id));
    }
}
